import { useMemo } from 'react';
import store from '@/store';
import { authPassed } from "@/utils";


const useAuth = (code) => {
    const {main={}} = store.getState(),
        permissions = main?.userInfo?.permissions || [],
        authCode = typeof code === 'string' ? code : (Object.prototype.toString.call(code) === '[object Object]' ? code?.code : '');

    const auth = useMemo(() => {
        return authPassed(authCode, permissions);
    }, [authCode, permissions]);

    return auth;
}

export default useAuth;